package org.fone.service.impl;

import cn.hutool.json.JSONObject;
import org.fone.service.UserService;
import org.fone.utils.RedisOperator;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    RedisOperator redisOperator;

    public UserServiceImpl(RedisOperator redisOperator) {
        this.redisOperator = redisOperator;
    }

    @Override
    public boolean saveDragInfo(String id, String data) {
        try {
            redisOperator.set(id,data);
            redisOperator.expire(id,15);
            return true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public JSONObject getDragInfo(String id) {
        try {
            return new JSONObject(redisOperator.get(id));
        }catch (Exception e){
            return null;
        }
    }
}
